import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Created whit IntelliJ IDEA.
 * Description：
 * User：ZHONGCHEN
 * Date:2022-03-21
 * Time:9:53
 */

/**
 * 653. 两数之和 IV - 输入 BST
 * 给定一个二叉搜索树 root 和一个目标结果 k，
 * 如果 BST 中存在两个元素且它们的和等于给定的目标结果，
 * 则返回 true
 */
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

public class TestDemo {
    //中序遍历+双指针
    public boolean findTarget(TreeNode root, int k) {
        ArrayList<Integer> list = intermediateSequence(root);
        int r = list.size() - 1;
        int l = 0;
        boolean ans = false;
        while (l <= r) {
            int left = list.get(l);
            int right = list.get(r);
            int sum = left + right;
            if (sum == k) {
                ans = true;
                break;
            }
            if (sum > k) {
                r--;
            } else {
                l++;
            }
        }
        return ans;
    }

    private ArrayList<Integer> intermediateSequence(TreeNode root) {
        ArrayList<Integer> list = new ArrayList<>();
        if (root == null) {
            return list;
        }
        list.addAll(intermediateSequence(root.left));
        list.add(root.val);
        list.addAll(intermediateSequence(root.right));
        return list;
    }

    //哈希表+前序序遍历
    /**
     * 在递归搜索过程中记录下相应的节点值（使用 Set 集合），
     * 如果在遍历某个节点 xx 时发现集合中存在 k - x.valk−x.val，
     * 说明存在两个节点之和等于 kk，返回 True，若搜索完整棵树都没有则返回 False
     */
    Set<Integer> set = new HashSet<>();

    public boolean findTarget1(TreeNode root, int k) {
        if (root == null) {
            return false;
        }
        if (set.contains(k - root.val)) {
            return true;
        }
        set.add(root.val);
        return findTarget1(root.left, k) | findTarget1(root.right, k);
    }

    //牛客-星际密码-Fibonacci数列问题
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int num = scanner.nextInt();
            for (int i = 0; i < num; i++) {
                int tmp = scanner.nextInt();
                System.out.printf("%04d", Fibonacci(tmp));
            }
            System.out.println();
        }
    }

    private static int Fibonacci(int tmp) {
        int[] fibonacci = new int[10001];
        fibonacci[0] = 0;
        fibonacci[1] = 1;
        fibonacci[2] = 2;
        for (int i = 3; i < 10001; i++) {
            fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];
            fibonacci[i] %= 10000;
        }
        return fibonacci[tmp];
    }

    //数根-输入的是字符串并且数值很大;用long都存不下
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            long ans = numRoot(Long.parseLong(scanner.next()));
            System.out.println(ans);
        }
    }

    private static long numRoot(long nextInt) {
        if (nextInt < 10) {
            return nextInt;
        }
        int ans = 0;
        while (nextInt >= 10) {
            while (nextInt != 0) {
                ans += nextInt % 10;
                nextInt /= 10;
            }
            if (ans > 10) {
                nextInt = ans;
                ans = 0;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String str = scanner.next();
            while (str.length() > 1) {
                int ans = 0;
                for (int i = 0; i < str.length(); i++) {
                    ans += str.charAt(i) - '0';
                }
                str = String.valueOf(ans);
            }
            System.out.println(str);
        }
    }
}